package com.example.awtEventHandle;

import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

/**
 * @Author 郅占伟
 * @ClassName MyWindowsListener
 * @Description TODO
 * @Date 2024年05月10日
 * @Version: 1.0
 */
public class MyWindowsListener implements WindowListener {

    @Override
    public void windowOpened(WindowEvent e) {

    }

    // 窗体关闭监听
    @Override
    public void windowClosing(WindowEvent e) {
        // 获取窗体实例
        Window window = e.getWindow();
        System.out.println("窗体关闭了");
        window.setVisible(false);
        window.dispose();
    }

    @Override
    public void windowClosed(WindowEvent e) {

    }

    @Override
    public void windowIconified(WindowEvent e) {

    }

    @Override
    public void windowDeiconified(WindowEvent e) {

    }

    // 窗体被激活时触发
    @Override
    public void windowActivated(WindowEvent e) {
        Window window = e.getWindow();
        System.out.println("窗体的宽度是：" + window.getWidth() + "窗体的高度是：" + window.getHeight());
    }

    @Override
    public void windowDeactivated(WindowEvent e) {

    }
}
